'use strict';

const {app, assert} = require('egg-mock/bootstrap');

describe('CollectApiTest', () => {
  let ctx;
  let mockUser;

  before(async function () {
    ctx = app.mockContext();
    mockUser = {id: '5c7cd4f781c857816114c940', access_token: 'edd8bcd1-db39-4ea8-8221-3849349eccc2'};

  });

  // 通过插件收藏
  it('POST /api/v1/collect/share should ok', async () => {
    let blog = {
      "title": "ThreadingTest（穿线测试）引领白盒测试进入工业界 - V2EX",
      "brief": "",
      "tab": "share",
      "is_public": true,
      "original_url": "https://www.v2ex.com/t/210378",
      "content": "https://www.v2ex.com/t/210378",
      "collect_tags": "测试",
      "access_token": "edd8bcd1-db39-4ea8-8221-3849349eccc2"
    };

    let result = await app.httpRequest()
      .post('/api/v1/collect/share')
      .send(blog);

    console.log(result.body);
    assert(result.body.status == 'success');
  });


  // 通过插件取消收藏
  it('POST /api/v1/collect/cancel_share should ok', async () => {
    let blog = {
      access_token: mockUser.access_token,
      topic_id: '5f6f36aaf7ed7095c01ea0bb'
    };

    let result = await app.httpRequest()
      .post('/api/v1/collect/cancel_share')
      .send(blog);

    console.log(result.body);
    assert(result.body.status == 'success');
  }).timeout(10000000);


  // 展示用户所有标签及标签包含文章的数量
  it('POST /api/v1/collect/listTags ok', async () => {
    const data = {
      access_token: mockUser.access_token,
      tag_name: '标签'
    }

    let result = await app.httpRequest()
      .post(`/api/v1/collect/listTags`)
      .send(data);

    console.log(result.body);
    assert(result.body.status == 'success');
  });


  // 展示用户所有标签及标签包含文章的数量+该链接是否已收藏(已收藏的情况)
  it('POST /api/v1/collect/showInfo has already collected', async () => {
    const original_url = 'https://www.zhihu.com/question/443280657/answer/1723664210'
    const data = {
      access_token: mockUser.access_token,
      original_url: original_url
    }
    let result = await app.httpRequest()
      .post(`/api/v1/collect/showInfo`)
      .send(data);

    console.log(JSON.stringify(result.body));
    assert(result.body.status == 'success');
  });


  // 展示用户所有标签及标签包含文章的数量+该链接是否已收藏(未收藏的情况)
  it('POST /api/v1/collect/showInfo has not collected', async () => {
    const original_url = 'https://www.wang1314.com/'
    const data = {
      access_token: mockUser.access_token,
      original_url: original_url
    }
    let result = await app.httpRequest()
      .post(`/api/v1/collect/showInfo`)
      .send(data);

    console.log(JSON.stringify(result.body));
    assert(result.body.status == 'success');
  });

});
